-- @Author: 作者QQ381990860
-- @Date:   2022-05-08 13:32:39
-- @Last Modified by:   作者QQ381990860
-- @Last Modified time: 2022-09-14 16:16:37
--======================================================================--
-- @作者: QQ381990860
-- @创建时间:   2019-12-03 02:17:19
-- @Last Modified time: 2021-02-01 16:16:44
--======================================================================--
local 场景类_精灵系统 = class(窗口逻辑)

local floor = math.floor
local format = string.format
local insert = table.insert
local remove = table.remove
local type = type
local mouseb = 引擎.鼠标弹起
local zts,zts1,zts2,tp
local 图像类 = require("gge图像类")

local function jp(zz,dj) --floor(user.角色.精灵.气血 + user.角色.精灵.等级*(user.角色.精灵.气血/1000)*250)
  local n = 0xFFFFFFFF
  if    (zz <= 1200 and dj ==1) or (zz <= 1800 and dj ==2)  or (zz <= 3150 and dj ==3)  or (zz <= 6300 and dj ==4)  or (zz <= 13126 and dj ==5)  or (zz <= 30713 and dj ==6) then
    n = 0xFF006633
  elseif (zz<= 1400 and dj ==1) or (zz <= 2100 and dj ==2)  or (zz <= 3675 and dj ==3)  or (zz <= 7350 and dj ==4)  or (zz <= 15751 and dj ==5)  or (zz <= 37800 and dj ==6) then
    n = 0xFF003399
  elseif (zz<= 1600 and dj ==1) or (zz <= 2400 and dj ==2)  or (zz <= 4200 and dj ==3)  or (zz <= 8400 and dj ==4)  or (zz <= 18376 and dj ==5)  or (zz <= 44887 and dj ==6) then
    n = 0xFF663399
  elseif (zz<= 1800 and dj ==1) or (zz <= 2700 and dj ==2)  or (zz <= 4725 and dj ==3)  or (zz <= 9450 and dj ==4)  or (zz <= 21001 and dj ==5)  or (zz <= 51974 and dj ==6) then
    n = 0xFFFF00FF
  elseif (zz<= 2000 and dj ==1) or (zz <= 3000 and dj ==2)  or (zz <= 5250 and dj ==3)  or (zz <= 10500 and dj ==4) or (zz <= 23625 and dj ==5)  or (zz <= 59062 and dj ==6) then
    n = 0xFFFF6600
  end

return n
end
local function jp1(zz,dj)

   local n = 0xFFFFFFFF
  if    (zz <= 120 and dj ==1) or (zz <= 180 and dj ==2)  or (zz <= 315 and dj ==3)  or (zz <= 630 and dj ==4)  or (zz <= 1312 and dj ==5)  or (zz <= 3071 and dj ==6) then
    n = 0xFF006633
  elseif (zz<= 140 and dj ==1) or (zz <= 210 and dj ==2)  or (zz <= 367 and dj ==3)  or (zz <= 735 and dj ==4)  or (zz <= 1575 and dj ==5)  or (zz <= 3780 and dj ==6) then
    n = 0xFF003399
  elseif (zz<= 160 and dj ==1) or (zz <= 240 and dj ==2)  or (zz <= 420 and dj ==3)  or (zz <= 840 and dj ==4)  or (zz <= 1837 and dj ==5)  or (zz <= 4488 and dj ==6) then
    n = 0xFF663399
  elseif (zz<= 180 and dj ==1) or (zz <= 270 and dj ==2)  or (zz <= 472 and dj ==3)  or (zz <= 945 and dj ==4)  or (zz <= 2100 and dj ==5)  or (zz <= 5197 and dj ==6) then
    n = 0xFFFF00FF
  elseif (zz<= 200 and dj ==1) or (zz <= 300 and dj ==2)  or (zz <= 525 and dj ==3)  or (zz <= 1050 and dj ==4) or (zz <= 2362 and dj ==5)  or (zz <= 5906 and dj ==6) then
    n = 0xFFFF6600
  end

return n


end


local function jp2(zz,dj)

   local n = 0xFF000000
    if zz == "幸运" then
    n = 0xFF003399
  elseif zz == "感知" then
    n = 0xFF663399
  elseif zz == "神佑" then
    n = 0xFFFF00FF
  elseif zz == "高神" or  zz == "聚灵术" or  zz == "聚财术" then
    n = 0xFFFF6600
  end

return n


end
local function qjy(zz)
  local n = 0xFFFFFFFF
  if zz <= 1 then
    n = 100
  elseif zz<= 2 then
    n = 500
  elseif zz<= 3 then
    n = 2000
  elseif zz<= 4 then
    n = 5000
  elseif zz<= 5 then
    n = 30000
  elseif zz<= 6 then
    n = 100000
  end

return n
end
local function qjy1(zz)
  local n = 0xFFFFFFFF
  if zz <= 1 then
    n = 1000
  elseif zz<= 2 then
    n = 5000
  elseif zz<= 3 then
    n = 20000
  elseif zz<= 4 then
    n = 50000
 elseif zz<= 5 then
    n = 300000
 elseif zz<= 6 then
    n = 1000000

  end

return n
end






function 场景类_精灵系统:初始化(根)
	self.ID = 5508
	self.x = 90+(全局游戏宽度-800)/2
	self.y = 77
	self.xx = 0
	self.yy = 0
	self.注释 = "精灵系统"
	self.可视 = false
	tp = 根
    zts2 = tp.字体表.描边字体
	self.焦点 = false
	self.可移动 = true
	local 资源 = 根.资源
	local 按钮 = 根._按钮
	local 自适应 = 根._自适应
	self.资源组 = {
		[1] = 自适应.创建(0,1,315,350,3,9),
		[2] = 按钮.创建(自适应.创建(18,4,16,16,4,3),0,0,4,true,true),
		[5] = 按钮.创建(自适应.创建(11,4,50,20,1,3),0,0,4,true,true,"激活"),
		[6] = 按钮.创建(自适应.创建(11,4,30,20,1,3),0,0,4,true,true,"驯"),
		[7] = 按钮.创建(自适应.创建(11,4,50,20,1,3),0,0,4,true,true,"祝福"),
		[8] =  自适应.创建(2,1,130,117,3,9),

		[17] = 按钮.创建(自适应.创建(11,4,24,20,1,3),0,0,4,true,true,"显"),
		[18] = 按钮.创建(自适应.创建(11,4,24,20,1,3),0,0,4,true,true,"关"),
		[19] = 按钮.创建(自适应.创建(11,4,24,20,1,3),0,0,4,true,true,"刷"),
		[20] = 按钮.创建(自适应.创建(11,4,24,20,1,3),0,0,4,true,true,"重"),

		[21] =  资源:载入('JM.dll',"网易WDF动画",0x3906F9F1),
        [22] = 按钮.创建(自适应.创建(11,4,30,20,1,3),0,0,4,true,true,"技"),
		[23] =  资源:载入('JM.dll',"网易WDF动画",0x3906F9F1),
		[24] = 按钮.创建(自适应.创建(11,4,30,20,1,3),0,0,4,true,true,"补"),
		[25] =  图像类(程序目录.."data/pic/技能格.png"),
		[26] =  图像类(程序目录.."data/pic/已开.png"),
		[27] =  图像类(程序目录.."data/pic/未开.png"),
		[28] =  图像类(程序目录.."data/pic/问号.png"),
		[29] = 按钮.创建(自适应.创建(30,4,26,26,4,1),0,0,5,true,true),
		[30] = 按钮.创建(自适应.创建(30,4,26,26,4,1),0,0,5,true,true),
	}

	self.资源组[29]:绑定窗口_(5508)
	self.资源组[29].允许再次点击 = true
	self.资源组[30]:绑定窗口_(5508)
	self.资源组[30].允许再次点击 = true

	self.技能 = {}
	self.主动技能 ={[1]={名称 ="落岩"},[2]={名称 ="上古灵符"},[3]={名称 ="地狱烈火"},[4]={名称 ="失心符"},[5]={名称 ="一笑倾城"},[6]={名称 ="扶摇万里"}}
	local 格子 = 根._技能格子

	self.小精灵 = {}
	self.资源组[99] = nil
	for n=1,6 do
	local jl = 	引擎.取精灵(n)
	self.小精灵[n] = 资源:载入(jl[4],"网易WDF动画",jl[1])
	self.技能[n] = 格子(0,0,n,"精灵技能栏")
	self.技能[n]:置技能(self.主动技能[n],"精灵")
	end

	for n=9,16 do
	self.资源组[n] = 自适应.创建(3,1,60,18,1,3)
	end
	self.圣兽丹动画 =根.资源:载入('JM.dll',"网易WDF动画",0xA4F1E391)


	self.资源组[2]:绑定窗口_(5508)
	self.资源组[6]:绑定窗口_(5508)
	self.资源组[7]:绑定窗口_(5508)
	self.资源组[5]:绑定窗口_(5508)
	self.资源组[17]:绑定窗口_(5508)
	self.资源组[18]:绑定窗口_(5508)
	self.资源组[19]:绑定窗口_(5508)
	self.资源组[20]:绑定窗口_(5508)
	self.资源组[22]:绑定窗口_(5508)
	self.资源组[24]:绑定窗口_(5508)

	self.选中 = nil

	zts = tp.字体表.华康字体
	zts1 = tp.字体表.华康字体
	self.窗口时间 = 0
end


function 场景类_精灵系统:打开(数据)
	if self.可视 then
		self.选中 = nil
		self.可视 = false
		self.资源组[99] = nil
	else
	local n = 取模型(tp.场景.人物.数据.造型)
		self.资源组[99] = tp.资源:载入(n.资源,"网易WDF动画",n["静立"])

   if  self.x > 全局游戏宽度 then
        self.x = 90+(全局游戏宽度-800)/2
    end
		self.数据 =数据

		insert(tp.窗口_,self)

		tp.运行时间 = tp.运行时间 + 1
	 	self.窗口时间 = tp.运行时间
	    self.可视 = true

	end
end
function 场景类_精灵系统:刷新(数据)

	   self.数据 =数据

end


function 场景类_精灵系统:显示(dt,x,y)
	self.焦点 = false
	self.资源组[2]:更新(x,y)
	self.资源组[5]:更新(x,y,self.数据.激活==0)
	self.资源组[7]:更新(x,y,self.数据.激活==1)
	self.资源组[6]:更新(x,y,self.数据.激活==1)
	self.资源组[24]:更新(x,y,self.数据.激活==1)
	self.资源组[17]:更新(x,y,self.数据.激活==1)
	self.资源组[18]:更新(x,y,self.数据.激活==1)
	self.资源组[19]:更新(x,y,self.数据.激活==1)
	self.资源组[20]:更新(x,y,self.数据.激活==1)
	self.资源组[22]:更新(x,y,self.数据.激活==1)

	if self.资源组[2]:事件判断() then
		self:打开()
		return false
    elseif self.资源组[5]:事件判断() then
	   客户端:发送数据(1,399, 5, "0")

    elseif self.资源组[6]:事件判断() then
	   客户端:发送数据(1,400, 5, "0")
	elseif self.资源组[20]:事件判断() then
	   客户端:发送数据(1,411, 5, "0")
	 elseif self.资源组[19]:事件判断() then
	   客户端:发送数据(1,422, 5, "0")
	   elseif self.资源组[17]:事件判断() then
	   客户端:发送数据(1,433, 5, "0")
	   elseif self.资源组[18]:事件判断() then
	   客户端:发送数据(1,444, 5, "0")
	    elseif self.资源组[24]:事件判断() then
	   客户端:发送数据(1,455, 5, "0")
	    elseif self.资源组[22]:事件判断() then
	   客户端:发送数据(1,466, 5, "0")
	    elseif self.资源组[7]:事件判断() then
	   客户端:发送数据(1,499, 5, "0")
	   elseif self.资源组[29]:事件判断() then
	   客户端:发送数据(1, 291, 13, "9", 1)
	   elseif self.资源组[30]:事件判断() then
	   客户端:发送数据(2, 291, 13, "9", 1)
	end
	self.资源组[1]:显示(self.x,self.y)
	self.资源组[8]:显示(self.x+34,self.y+34)
	self.资源组[17]:显示(self.x+5,self.y+45)
	self.资源组[18]:显示(self.x+5,self.y+70)
	self.资源组[19]:显示(self.x+5,self.y+95)
	self.资源组[20]:显示(self.x+5,self.y+120)
	self.资源组[22]:显示(self.x+158,self.y+227,true,1)
	tp.窗口标题背景_:显示(self.x+self.资源组[1].宽度/2-90,self.y)
	self.资源组[2]:显示(self.x+298,self.y+3)

	    self.资源组[29]:更新(x,y,self.数据.主动开关 ~= 1)
		self.资源组[29]:显示(self.x+23,self.y+278,true,nil,nil,self.数据.主动开关==1,4)

		self.资源组[30]:更新(x,y,self.数据.主动开关 ~= 2)
		self.资源组[30]:显示(self.x+23,self.y+302,true,nil,nil,self.数据.主动开关==2,4)


		self.圣兽丹动画:显示(self.x+133,self.y+122)
      if self.圣兽丹动画:是否选中(x,y) then
	       if self.数据[1] and #self.数据[1] >0 then
		     local 效果 = {}
		      for n=1,#self.数据[1] do
			    效果[n] = "#G/"..self.数据[1][n].类型.."+"..self.数据[1][n].数值.." #Y/有效期: #G/"..math.floor((self.数据[1][n].时间-os.time())/3600).."小时\n"
			  end
		      tp.提示:自定义(x+110,y,"#y/祝福效果:\n"..(效果[1] or "")..(效果[2] or "")..(效果[3] or "")..(效果[4] or "")..(效果[5] or "")..(效果[6] or ""))
		   else
              tp.提示:自定义(x+110,y,"#y/祝福效果:#G/ 无")
		   end
	  end
		self.资源组[99]:更新(dt)
		self.资源组[99]:显示(self.x + 94+150-165+10,self.y + 283-142-10)
		 tp.影子:显示(self.x + 94+150-165+10,self.y + 283-142-10)


	zts1:置颜色(0xFFFFFFFF):显示(self.x+120,self.y+3,"精灵系统")
	tp.字体表.普通字体:置颜色(0xFFFFFFFF):显示(self.x+4,self.y+282,"参:")
	tp.字体表.普通字体:置颜色(0xFFFFFFFF):显示(self.x+4,self.y+308,"休:")

	self.资源组[5]:显示(self.x+15,self.y+227,true,1)
	self.资源组[6]:显示(self.x+158,self.y+164,true,1)
	self.资源组[24]:显示(self.x+158,self.y+193,true,1)

	self.资源组[7]:显示(self.x+95,self.y+227,true,1)

	self.资源组[28]:显示(self.x+290+8,self.y+265-3)

	    if self.资源组[28]:检查点(x,y)  then
           tp.提示:自定义(x+40,y,"#G/精灵主动技能开启后,战斗中每回合都有几率额外随机释放已开启的主动技能\n#Y/精灵等级>=1,自动开启第一技能\n#Y/精灵等级>=2,自动开启第二技能\n#Y/精灵等级>=3,自动开启第三技能\n#Y/精灵等级>=4,自动开启第四技能\n#Y/精灵等级>=5,自动开启第五技能\n#Y/精灵等级>=6,自动开启第六技能\n")
        end

    tp.字体表.普通字体:置颜色(0xFFFFFFFF):显示(self.x+197,self.y+35,"等级\n\n气血\n\n魔法\n\n伤害\n\n防御\n\n速度\n\n灵力\n\n技能")

	tp.字体表.华康字体:置颜色(0xFF006633):显示(self.x+173,self.y-6+36,"■\n↓")
	tp.字体表.华康字体:置颜色(0xFF003399):显示(self.x+173,self.y-6+64,"■\n↓")
    tp.字体表.华康字体:置颜色(0xFF663399):显示(self.x+173,self.y-6+92,"■\n↓")
	tp.字体表.华康字体:置颜色(0xFFFF00FF):显示(self.x+173,self.y-6+120,"■\n↓")
	tp.字体表.华康字体:置颜色(0xFFFF6600):显示(self.x+173,self.y-6+148,"■")

     --if self.数据.主动开关 == 1  then
      self.资源组[25]:显示(self.x+130-85-15+15,self.y+279)
	-- end
    local xx = 0
	for w=1,6 do
	if self.数据.主动开关 == 1  then
		self.技能[w]:置坐标(self.x+130+3-82-15+13+xx*41,self.y+280+4)
		 self.技能[w]:显示(x,y,self.鼠标)

		 if self.数据.主动技能 and self.数据.主动技能[w]~= nil  then
		    self.资源组[26]:显示(self.x+130+1-82-15+13+xx*41,self.y+280+4)
			else
			self.资源组[27]:显示(self.x+130+1-82-15+13+xx*41,self.y+280+4)
		 end
		 if self.技能[w].焦点 and self.技能[w].技能 ~= nil then
	   	    	tp.提示:BB技能(x,y,self.技能[w].技能)
	   	  end
		end
	   xx = xx +1
	end


	tp.字体表.普通字体:置颜色(0xFFFFFFFF):显示(self.x+10,self.y+167,"经验\n\n能量")
	tp.经验背景1_:显示(self.x+43,self.y+164)
	tp.经验背景1_:置宽高1(110,19)  --186 19
	tp.经验背景2_:显示(self.x+43,self.y+192)
	tp.经验背景2_:置宽高1(110,19)  --186 19
	 for n=9,16 do 
	  self.资源组[n]:显示(self.x+238,self.y+32+((n-9)*33))
	 end
	 if self.数据~=nil then 
	 self.小精灵[self.数据.等级]:更新(dt)
	 self.小精灵[self.数据.等级]:显示(self.x+104,self.y+130)
	 if self.数据.激活==1 then 
	    self.资源组[21]:置区域(0,0,math.min(math.floor(self.数据.经验 / qjy(self.数据.等级)*100),100),16)
        self.资源组[21]:显示(self.x+48,self.y+167)
		self.资源组[23]:置区域(0,0,math.min(math.floor(self.数据.能量 / qjy1(self.数据.等级)*100),100),16)
        self.资源组[23]:显示(self.x+48,self.y+195)
	    zts2:置描边颜色(-16240640)
        zts2:置颜色(4294967295)
        zts2:显示(self.x + ((272 - zts2:取宽度(ts))/2)-54,self.y + 166,self.数据.经验.."/"..qjy(self.数据.等级))
		zts2:显示(self.x + ((272 - zts2:取宽度(ts))/2)-54,self.y + 194,self.数据.能量.."/"..qjy1(self.数据.等级))
	    
	    tp.字体表.华康字体:置颜色(0xFF000000):显示(self.x+260,self.y+35,self.数据.等级)
	   	
		
		tp.字体表.华康字体:置颜色(jp(self.数据.气血,self.数据.等级)):显示(self.x+248,self.y+65,self.数据.气血)
		tp.字体表.华康字体:置颜色(jp(self.数据.魔法,self.数据.等级)):显示(self.x+248,self.y+97,self.数据.魔法)
		tp.字体表.华康字体:置颜色(jp1(self.数据.伤害,self.数据.等级)):显示(self.x+248,self.y+129,self.数据.伤害)
		tp.字体表.华康字体:置颜色(jp1(self.数据.防御,self.数据.等级)):显示(self.x+248,self.y+165,self.数据.防御)
		tp.字体表.华康字体:置颜色(jp1(self.数据.速度,self.数据.等级)):显示(self.x+248,self.y+196,self.数据.速度)
		tp.字体表.华康字体:置颜色(jp1(self.数据.灵力,self.数据.等级)):显示(self.x+248,self.y+230,self.数据.灵力)
		tp.字体表.华康字体:置颜色(jp2(self.数据.技能)):显示(self.x+248,self.y+261,self.数据.技能)
		
		
	 end
	 else 
	 tp.字体表.普通字体:置颜色(0xFF000000):显示(self.x+260,self.y+35,self.数据.等级.."\n\n加载中\n\n加载中\n\n加载中\n\n加载中\n\n加载中\n\n加载中") 
	 end
	 
	 
	 
	 
	 

	local xx = 0
	local yy = 1
	
	
	-- zts:置颜色(-16777216)
	-- zts:置颜色(-256)

end







return 场景类_精灵系统